<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>ReactAjax</title>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>
    <script src="js/browser.min.js"></script>
    <script src="js/JSXTransformer.js"></script>
    <script src="js/jquery-1.11.3.js"></script>
</head>
<body>
    <div id="example"></div>

    <script type="text/babel">
        var source = "https://api.github.com/users/octocat/gists" ;
        var UserGist = React.createClass({
            getInitialState:function(){
                return {
                    userName:"",
                    lastGistUrl:""
                };
            },
            componentDidMount:function(){
                this.serverRequest = $.get(this.props.source,function(result){
                    var lastGist = result[0] ;
                    this.setState({
                        userName:lastGist.owner.login,
                        lastGistUrl:lastGist.html_url
                    });
                }.bind(this));
            },
            componentWillUnmount:function(){
                this.serverRequest.abort();
            },

            render:function(){
                return (
                        <div>
                        {this.state.userName} 用户最新的Gist共享地址：
                        <a href={this.state.lastGistUrl}>{this.state.lastGistUrl}</a>
                        </div>
                );
            }
        });

        ReactDOM.render(
                <UserGist source={source} />,
                document.getElementById('example')
        );

    </script>
</body>
</html>